package org.example.mall.Controller;

import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.example.mall.Pojo.Result;
import org.example.mall.utils.JwtUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@Controller
@RestController
@RequestMapping("/Article")
public class JwtTestController {

    //查询商品列表接口
    @RequestMapping(value="/List",method = RequestMethod.GET)
    //提取HTTP请求头中的Authorization字段值,获取response对象
    public Result<String> list(/*@RequestHeader(name = "Authorization") String token, HttpServletResponse response*/){
//        //验证Token，若校验失败则进入catch
//        try {
//            Map<String, Object> claims = JwtUtil.parseToken(token);
//            return Result.success("所有的商品数据...");
//        } catch (Exception e) {
//            //http响应状态码401
//            response.setStatus(401);
//            return Result.error("未登录");
//        }
        //有了拦截器以后，上面的就不需要了
        return Result.success("所有的商品数据...");
    }
}
